package com.example.democrud;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.api.R;
import com.example.democrud.enums.ResponseEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName ResponseVO
 * @Author Administrator
 * @Date 2020/4/22   14:43
 */
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseVO<T> {
    //返回状态码
    private Integer status ;
    //返回描述信息
    private String msg;
    //返回数据
    private T data;

    public ResponseVO(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public ResponseVO(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }


    public  static <T>ResponseVO<T> error(Integer status , String  msg){
        return new ResponseVO<>(status,msg);
    }

    public static <T>ResponseVO<T>error(ResponseEnum responseEnum){
        return error(responseEnum.getCode(),responseEnum.getDesc());
    }

    public static <T>ResponseVO<T>error(ResponseEnum responseEnum,String msg){
        return error(responseEnum.getCode(),msg);
    }

    public  static <T>ResponseVO<T> success(Integer status , String  msg, T data){
        return new ResponseVO<>(status,msg,data);
    }

    public  static <T>ResponseVO<T> success(Integer status , String  msg){
        return success(status,msg,null);
    }

    public  static <T>ResponseVO<T> success(){
        return success(ResponseEnum.SUCCESS.getCode(),ResponseEnum.SUCCESS.getDesc());
    }

    public  static <T> ResponseVO<T> success(String  msg){
        return success(ResponseEnum.SUCCESS.getCode(),msg);
    }

    public  static <T> ResponseVO<T> success(String  msg,T data){
        return success(ResponseEnum.SUCCESS.getCode(),msg,data);
    }

    public  static <T> ResponseVO<T> successData(T data){
        return success(ResponseEnum.SUCCESS.getCode(),ResponseEnum.SUCCESS.getDesc(),data);
    }

}
